package com.mouse.demo;

import com.mouse.damo.micro.*;
import com.mouse.haoi.service.CustomService;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestMstsc {
    private final static CustomService customService = new CustomService();


    public static void main(String[] args) {
        executeCmd("mstsc C:\\Users\\pc-001\\Desktop\\190.168.1.83.rdp");
        Com com = new Com();
        com.setResourcePath("D:\\tmp");
        Window window = new Window(com);
        List<Integer> hwndList = new ArrayList<>();
        boolean loopFlag = customService.loop(10 * 1000, () -> {
            int hwnd = window.findWindow(0, "TscShellContainerClass", "190.168.1.83");
            if (hwnd != 0) {
                hwndList.add(hwnd);
                return true;
            }
            return false;
        });
        if (!loopFlag) return;
        Integer hwnd = hwndList.get(0);
        System.out.println(hwnd);
//        window.setWindowMaximizeAndActivate(hwnd);
        window.setWindowState(hwnd, 1);
        Sleep.sleep(50);
//        System.out.println(bind);
        Mouse mouse = new Mouse(com);
//        mouse.mouseClick(42, 139, true);
//        mouse.mouseClick(42, 139, true);
        FindPic findPic = new FindPic(com);
        boolean winLoopFlag = customService.loop(15 * 1000, () ->
                findPic.findPicExist(0, 900, 500, 1080, "win.bmp", "203040", 0.8, 0)
                        ||findPic.findPicExist(0, 900, 500, 1080, "win1.bmp", "203040", 0.8, 0));
        if (!winLoopFlag) return;
        Sleep.sleep(50);
        mouse.mouseClick(20, 1060, true);
        Press press = new Press(com);
        Sleep.sleep(200);
        press.keyPress(Press.C);
        press.keyPress(Press.M);
        press.keyPress(Press.D);
//        window.sendString(hwnd, "cmd");
        Sleep.sleep(50);
        press.keyPress(Press.ENTER);

        Sleep.sleep(1000);
        press.keyPress(Press.N);
        press.keyPress(Press.O);
        press.keyPress(Press.T);
        press.keyPress(Press.E);
        press.keyPress(Press.P);
        press.keyPress(Press.A);
        press.keyPress(Press.D);
        press.keyPress(Press.ENTER);

        Sleep.sleep(5000);
        window.setWindowDestroy(hwnd);
    }

    private static Map<String, String> executeCmd(String cmd) {
        Runtime rt = Runtime.getRuntime(); // 运行时系统获取
        Map<String, String> lineMap = new HashMap<>();//存放返回值
        try {
            Process proc = rt.exec(cmd);// 执行命令
        } catch (IOException e) {
            e.printStackTrace();
        }
        return lineMap;
    }
}
